<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 药品出库记录
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
            </div>



            <el-table :data="tableList" border class="table" ref="multipleTable" header-cell-class-name="table-header">
                <el-table-column type="index" label="ID" width="55" align="center"></el-table-column>
                <el-table-column prop="shopName" label="门店" width="200" align="center"></el-table-column>

                <el-table-column prop="appenderName" label="供应商名称" width="200" align="center"></el-table-column>
                <el-table-column prop="drugId"  label="药品名称" width="210"></el-table-column>

                <el-table-column prop="specName"  label="规格" width="50" align="center"></el-table-column>
                <el-table-column prop="drugStock"  label="出库数量" width="80"></el-table-column>

<!--                <el-table-column prop="drugPrice"  label="单价" width="100"></el-table-column>-->

                <el-table-column   label="有效期" width="160" align="center">
                    <template #default="scope">
                        <el-date-picker
                                v-model="scope.row.validDate"
                                type="date"
                                placeholder="Select date and time"
                                :readonly=true
                                style="width:135px"

                        ></el-date-picker>
                    </template>
                </el-table-column>

<!--                <el-table-column label="入库日期" prop="operateTime" width="160" align="center"></el-table-column>-->
                <el-table-column label="出库日期" prop="operateTime" width="160" align="center"></el-table-column>

            </el-table>
<!--            <div class="pagination">-->
<!--                <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex"-->
<!--                               :page-size="query.pageSize" :total="pageTotal"-->
<!--                               @current-change="handlePageChange"></el-pagination>-->
<!--            </div>-->
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" v-model="editVisible" width="30%">
            <el-form label-width="70px">
                <el-form-item label="用户名">
                    <el-input v-model="form.name"></el-input>
                </el-form-item>
                <el-form-item label="地址">
                    <el-input v-model="form.address"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="editVisible = false">取 消</el-button>
                    <el-button type="primary" @click="saveEdit">确 定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script>
    import {ref, reactive} from "vue";
    import {ElMessage, ElMessageBox} from "element-plus";
    import {dateFormat} from "../utils/DateFormatteraUtil";
    import {queryOutList, queryTypeList,queryLogList} from "../api/index";
    import {STYLE_CONFIG} from "../utils/TotalCSSConfig";


    export default {
        name: "tableout",
        inject: ['reload'],
        data() {
            return {
                selectList: [],
                CSS_CONFIG: STYLE_CONFIG,
                selectIds: [],
            }
        },
        setup() {
            const tableList = ref([]);
            const pageInfo = ref({});
            // 获取表格数据
            const getData = () => {
                queryOutList({operateType: 1}).then((res) => {
                    tableList.value = res.data.records
                });
            };
            const appenderList = ref([]);
            const shopList = ref([]);
            const specList = ref([]);
            queryTypeList('Appender').then((res) => {
                appenderList.value = res.data
            });
            queryTypeList('Shop').then((res) => {
                shopList.value = res.data
            });
            queryTypeList('Spec').then((res) => {
                specList.value = res.data
            });
            getData();


            return {
                tableList,
                pageInfo,
                appenderList,
                shopList,
                specList,
            };
        },
        methods: {
            // 新增
            add: function () {
                this.addList.push({
                    drugID: null,
                    drugCount: null,
                    drugPrice: null,
                    operateTime: dateFormat("YYYY-mm-dd HH:MM:SS", new Date()).toLocaleString(),
                    operateType: "0"
                })
                console.log(this.addList)
            },
            // 提交
            submit: function () {
                let data = [];
                this.selectList.forEach(item => {
                    data.push({drugStockId: item.logId, drugOutCount: item.drugOutCount})
                })
                drugOut(data).then((res) => {
                    // 刷新页面
                    this.reload();
                });
            },
            selectRaw(val) {
                this.selectList = val;
                this.selectIds = [];
                this.selectList.forEach(item => {
                    this.selectIds.push(item.logId)
                })
                this.tableList.forEach(line =>{
                    if(this.selectIds.indexOf(line.logId) !=-1){

                        line.editFlag = true;
                    }
                    else {
                        line.editFlag = false;
                    }
                })
                console.log(this.selectIds);

            },
        }
    }
</script>

<style scoped>
    .handle-box {
        margin-bottom: 20px;
    }

    .handle-select {
        width: 120px;
    }

    .handle-input {
        width: 300px;
        display: inline-block;
    }

    .table {
        width: 100%;
        font-size: 14px;
    }

    .red {
        color: #ff0000;
    }

    .mr10 {
        margin-right: 10px;
    }

    .mr5 {
        margin-right: 5px;
    }

    .table-td-thumb {
        display: block;
        margin: auto;
        width: 40px;
        height: 40px;
    }
</style>
